﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
	/// <summary>
	/// 前台栏目控制类对象
	/// </summary>
	/// <![CDATA[2014-8-18 18:34:27]]>
	private DLL.WebColumn.Component clsWebColumnComp;
	private DLL.TrainingOrganization.Component clsTrainingOrganizationComp;

	protected void Page_Load(object sender, EventArgs e)
	{
		ShowMainMenu();
		ShowFriendlyLink();
	}

	protected override void OnInit(EventArgs e)
	{
		clsWebColumnComp = new DLL.WebColumn.Component(Page);
		clsTrainingOrganizationComp = new DLL.TrainingOrganization.Component(Page);

		base.OnInit(e);
	}

	private void ShowMainMenu()
	{
		MenuItem mItemIndex = new MenuItem();
		MenuItem mItemZX = new MenuItem();		// 培训资讯
		MenuItem mItemZCWJ = new MenuItem();		// 政策文件
		MenuItem mItemKJCS = new MenuItem();        // 课件超市
		MenuItem mItemPXJG = new MenuItem();		// 培训机构
		MenuItem mItemZXXX = new MenuItem();		// 在线学习
		MenuItem mItemDSZX = new MenuItem();		// 大师在线
		MenuItem mItemPXDT = new MenuItem();		// 培训动态
		MenuItem mItemLYB = new MenuItem();		// 留言板
		MenuItem mItemAdmin = new MenuItem();		// 网站管理
		MenuItem mItemPXGL = new MenuItem();		// 培训管理
		//MenuItem mItemKJCS = new MenuItem();		// 课件超市

		mItemIndex.Text = "首页";
		mItemZX.Text = "培训资讯";
		mItemZCWJ.Text = "政策文件";
		mItemKJCS.Text = "课件超市";
		mItemPXJG.Text = "培训机构";
		mItemZXXX.Text = "在线学习";
		mItemDSZX.Text = "大师之家";
		mItemPXDT.Text = "培训动态";
		mItemLYB.Text = "留言板";
		mItemAdmin.Text = "网站管理";
		mItemPXGL.Text = "培训管理";
		//mItemKJCS.Text = "课件超市";

		mItemIndex.NavigateUrl = "~/Default.aspx";
		mItemZX.NavigateUrl = "~/WebColumnMore.aspx?WebColumnID=10";
		mItemZCWJ.NavigateUrl = "~/WebColumnMore.aspx?WebColumnID=11";
		mItemPXDT.NavigateUrl = "~/WebColumnMore.aspx?WebColumnID=1";
		mItemZXXX.NavigateUrl = "~/OnLineLearnMore.aspx";
		mItemDSZX.NavigateUrl = "http://172.16.8.163:81";
		mItemLYB.NavigateUrl = "~/Message.aspx";
		mItemPXGL.NavigateUrl = "http://172.16.8.163:100";
		mItemKJCS.NavigateUrl = "~/CoursewareMore.aspx";

		mItemAdmin.NavigateUrl = "~/Admin/Login.aspx";
		mItemAdmin.Target = "_blank";
		mItemDSZX.Target = "_blank";
		mItemPXGL.Target = "_blank";
		mItemKJCS.Target = "_blank";

		AddChildMenu(mItemZCWJ, 11);
		AddChildMenu(mItemPXDT, 1);

		ShowDepartmentLink(mItemPXJG);

		MainMenu.Items.Clear();

		
		MainMenu.Items.Add(mItemIndex);

		MainMenu.Items.Add(mItemPXDT);
		MainMenu.Items.Add(mItemZX);
		MainMenu.Items.Add(mItemZXXX);
		MainMenu.Items.Add(mItemDSZX);
		MainMenu.Items.Add(mItemZCWJ);

		
		MainMenu.Items.Add(mItemKJCS);
		MainMenu.Items.Add(mItemPXJG);
		
		
		
		MainMenu.Items.Add(mItemLYB);
		MainMenu.Items.Add(mItemPXGL);
		MainMenu.Items.Add(mItemAdmin);
	}

	/// <summary>
	/// 给一个栏目添加下级栏目
	/// </summary>
	/// <![CDATA[2014-8-18 18:35:44]]>
	/// <param name="mItem"></param>
	/// <param name="nParentWebColumnID"></param>
	private void AddChildMenu(MenuItem mItem, int nWebColumnID)
	{
		List<DLL.WebColumn.Entity> list = new List<DLL.WebColumn.Entity>();

		list = clsWebColumnComp.QueryByParent(nWebColumnID);
		for (int i = 0; i < list.Count; i++)
		{
			MenuItem mItemChild = new MenuItem();

			mItemChild.Text = list[i].ColumnName;
			mItemChild.NavigateUrl = "~/WebColumnMore.aspx?WebColumnID=" + list[i].ID.ToString();

			mItem.ChildItems.Add(mItemChild);
		}
	}

	private void ShowDepartmentLink(MenuItem mItem)
	{
		//DLL.DepartmentLink.Component clsDepartmentLinkComp = new DLL.DepartmentLink.Component(Page);
		//List<DLL.DepartmentLink.Entity> listDepartmentLink = new List<DLL.DepartmentLink.Entity>();

		//listDepartmentLink = clsDepartmentLinkComp.QueryNoParent();
		//for (int i = 0; i < listDepartmentLink.Count; i++)
		//{
		//        MenuItem mItemChild = new MenuItem();

		//        mItemChild.Text = listDepartmentLink[i].DepartmentName;
		//        mItemChild.NavigateUrl = listDepartmentLink[i].Link;
		//        mItemChild.Target = "_blank";

		//        ShowChildDepartmentLink(mItemChild, listDepartmentLink[i].ID);

		//        mItem.ChildItems.Add(mItemChild);
		//}
		List<DLL.TrainingOrganization.Entity> list = new List<DLL.TrainingOrganization.Entity>();

		list = clsTrainingOrganizationComp.QueryAll();
		for (int i = 0; i < list.Count; i++)
		{
			MenuItem mItemChild = new MenuItem();

			mItemChild.Text = list[i].Name;
			mItemChild.NavigateUrl = list[i].Link;
			mItemChild.Target = "_blank";

			mItem.ChildItems.Add(mItemChild);
		}
	}
	//private void ShowChildDepartmentLink(MenuItem mItem, int nParentID)
	//{
	//        DLL.DepartmentLink.Component clsDepartmentLinkComp = new DLL.DepartmentLink.Component(Page);
	//        List<DLL.DepartmentLink.Entity> listDepartmentLink = new List<DLL.DepartmentLink.Entity>();

	//        listDepartmentLink = clsDepartmentLinkComp.QueryByParentID(nParentID);
	//        for (int i = 0; i < listDepartmentLink.Count; i++)
	//        {
	//                MenuItem mItemChild = new MenuItem();

	//                mItemChild.Text = listDepartmentLink[i].DepartmentName;
	//                mItemChild.NavigateUrl = listDepartmentLink[i].Link;
	//                mItemChild.Target = "_blank";

	//                ShowChildDepartmentLink(mItemChild, listDepartmentLink[i].ID);

	//                mItem.ChildItems.Add(mItemChild);
	//        }
	//}

	/// <summary>
	/// 显示友情链接
	/// </summary>
	private void ShowFriendlyLink()
	{
		DLL.FriendlyLink.Component clsFriendlyLinkComp = new DLL.FriendlyLink.Component(Page);
		List<DLL.FriendlyLink.Entity> listFriendlyLink = new List<DLL.FriendlyLink.Entity>();

		listFriendlyLink = clsFriendlyLinkComp.QueryAll();
		for (int i = 0; (i < listFriendlyLink.Count) && (i < 6); i++)
		{
			HyperLink hLinkPic = new HyperLink();

			if (i == 0)
			{
				hLinkPic.CssClass = "FriendLinkTextPic";
			}
			else
			{
				hLinkPic.CssClass = "FriendlyLink";
			}
			

			hLinkPic.ImageUrl = "~/ShowFileContent.aspx?FileContentID=" + listFriendlyLink[i].ImageID.ToString();
			hLinkPic.Target = "_blank";
			hLinkPic.NavigateUrl = listFriendlyLink[i].Link;

			PFriendlyLink.Controls.Add(hLinkPic);
		}
	}
}
